from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import  Column, Integer, String,create_engine,MetaData
from sqlalchemy.orm import sessionmaker
from sqlalchemy.schema import CreateTable, CreateColumn


mysql_options = dict(
    host="127.0.0.1",
    port=3306,
    database="studydb",
    user="root",
    password="123456"
)

DB_URL = f"mysql+pymysql://{mysql_options['user']}:{mysql_options['password']}@{mysql_options['host']}:{mysql_options['port']}/{mysql_options['database']}"


engine = create_engine(DB_URL)

Base = declarative_base(engine)  # SQLORM基类
session = sessionmaker(engine)()  # 构建session对象

class Student(Base):
    __tablename__ = 'employee1'  # 表名
    id = Column(Integer, primary_key=True, autoincrement=True)
    name = Column(String(50))
    age = Column(String(10))
    sex = Column(String(10))

class_tables = Base.metadata.sorted_tables # 将要这一次加载的表格
MATA_DATA = MetaData(bind=engine, reflect=True)
print(CreateTable(class_tables[0]))
class_tables[0].columns
db_tables = MATA_DATA.sorted_tables # 数据库中存在的表格


